<?php

require_once './include/common.inc.php';
require_once 'left.php';
require_once 'right.php';

$page_title = 'Acuity World´s WebShop';
$menu_id = 0;
$menu_str = PrintMenu();
$alert_message = '';

$reg_succeed = 0;
$alert_msg = '';
$faq_alert_ary = array(
'faq1' => 'Du har valgt træning/produkter i kommision.',
'faq2' => 'Jeg vil gerne have min kommision indbetalt på min konto.',
'faq3' => 'Du har læst og accepterer Acuity World´s WebShop Promoter aftale.',
'faq4' => 'Du har læst og accepterer Acuity World´s WebShop Salgs- og leveringsbetingelser.',
'faq5' => 'Du har tilføjet dit navn til Acuity World´s WebShop Promoter liste',
'faq6' => 'Du vil gerne have et link til din hjemmeside på Acuity World´s WebShop.',
'faq7' => 'Du vil gerne modtage vores banner for din hjemmeside.',
'faq8' => 'Du har valgt at modtage Acuity World`s nyhedsbrev på email.',
);

$act = $_POST['act'];

if ($act == "pregister") {
    
    $email = $_POST['email']; 
    $company = filter($_POST['company']); 
    $firstname =htmlspecialchars($_POST['firstname']); 
    $lastname =htmlspecialchars($_POST['lastname']); 
    $website =filter($_POST['website']); 
    
    $street =filter($_POST['street']); 
    $city =filter($_POST['city']); 
    $state =filter($_POST['state']); 
    $zip =filter($_POST['zip']); 
    $country =filter($_POST['country']); 
    
    $street2 =filter($_POST['street2']); 
    $city2 =filter($_POST['city2']); 
    $state2 =filter($_POST['state2']); 
    $zip2 =filter($_POST['zip2']); 
    $country2 =filter($_POST['country2']); 
    
    $phone1 = $_POST['phone1'];
    $phone = filter($phone1 . "||" . $_POST['phone']);
    $mobile1 = $_POST['mobile1'];
    $mobile = filter($mobile1 . "||" . $_POST['mobile']);
    $fax1 = $_POST['fax1'];
    $fax = filter($fax1 . "||" . $_POST['fax']);
    
    
    $b_bank =filter($_POST['bank']);
    $b_registration =filter($_POST['registration']);
    $b_account = filter($_POST['account']);
    $b_iban = filter($_POST['iban']);
    $b_swift = filter($_POST['swift']);
    
    $rank = 0;
    $status = 0;    
    
    
    $faq1 = isset($_POST['faq1']) && $_POST['faq1'] == 1 ? 1 : 0;
    $faq2 = $faq1 == 0 ? 1 : 0;
    $faq3 = isset($_POST['faq3']) && $_POST['faq3'] == 1 ? 1 : 0;
    $faq4 = isset($_POST['faq4']) && $_POST['faq4'] == 1 ? 1 : 0;
    $faq5 = isset($_POST['faq5']) && $_POST['faq5'] == 1 ? 1 : 0;
    $faq6 = isset($_POST['faq6']) && $_POST['faq6'] == 1 ? 1 : 0;
    $faq7 = isset($_POST['faq7']) && $_POST['faq7'] == 1 ? 1 : 0;
    $faq8 = isset($_POST['faq8']) && $_POST['faq8'] == 1 ? 1 : 0;
    
    
    //echo "<pre>";print_r($_POST);exit;
    
    if (trim($email) == "" || trim($firstname) == "" || trim($lastname) == "" ||
    trim($street) == "" || trim($city) == "" || trim($state) == "" || trim($zip) == "" || trim($country) == "" || trim($phone1) == "" || trim($phone) == "" ) {
        echo "<script>alert('Felter markeret med * skal udfyldes.');history.back();</script>";
        exit;
    }
    
    
    if (!preg_match("/[a-z0-9\.]{2,}@[a-z0-9]{2,}\.[a-z0-9]+/", $email)) {
        echo "<script>alert('Ugyldig email, prøv venligst igen.');history.back();</script>";
        exit;
    }
    
    // жemailΨһ
    $sql = "SELECT `id` FROM `promoter_info` WHERE `email` = '$email'";
    $rs = $db->get_one($sql);
    if (!empty($rs)) {
        echo "<script>alert('Email adresse eksisterer.');history.back(1);</script>";
        exit();
    }
    
    
    
    $sql = "INSERT INTO `promoter_info` (`email` , `company` , `website`, `firstname` , `lastname` , `street` , `city` , `state` , `zip` , `country` , `street2` , `city2` , `state2` , `zip2` , `country2` , `phone` , `mobile` , `fax`, `b_bank`, `b_registration`, `b_account`, `b_iban`, `b_swift` , `faq1` , `faq2` , `faq3` , `faq4` , `faq5` , `faq6` , `faq7` , `faq8` , `rank` , `status` , `date` ) 
            VALUES ('$email', '$company', '$website', '$firstname', '$lastname', '$street', '$city', '$state', '$zip', '$country', '$street2', '$city2', '$state2', '$zip2', '$country2', '$phone', '$mobile', '$fax', '$b_bank', '$b_registration', '$b_account', '$b_iban', '$b_swift', '$faq1', '$faq2', '$faq3', '$faq4', '$faq5', '$faq6', '$faq7', '$faq8', '$rank', '$status', '$timestamp'
            )";
    $db->query($sql);
    $promoter_uid = $db->insert_id();
    
    $email_faq_str = '';
    foreach($faq_alert_ary as $k=>$v) {
        if ($$k) {
            $alert_msg .= "<li>" . $v . "</li>\r\n";
            $email_faq_str .= '<tr>
                                 <td valign=top>
                                   <p>' . $v . '</p>
                                 </td>
                                 <td valign=top><p align=center>
                                   <INPUT TYPE=checkbox CHECKED NAME=' . $k . ' VALUE=1>
                                 </p></td>
                                </tr>';
        }
    }
    
    // ʼ send_email
    $show_name = empty($lastname) ? $firstname : $firstname . ' ' . $lastname;
    $reg_time = date("Y-m-d", $timestamp);
    $faq2_show = $faq2==1 ? "Yes" : "No";
    
    require_once './mail/promoter_to_members.php';
    sendhtmlmail($from_name,$from_email,$to_name,$to_email,$subject,$content);
    
    require_once './mail/promoter_to_webmaster.php';
    sendhtmlmail($from_name,$from_email,$to_name,$to_email,$subject,$content);
    
    Cookie("webshoppromoter",base64_encode($promoter_uid."\t".$email."\t".$timestamp), $cookietime); 
    $reg_succeed = 1;
    
    
    
}


require_once PrintEot('header');
require_once PrintEot('left');
require_once PrintEot('promoter_signup');
require_once PrintEot('right');
require_once PrintEot('footer');

?>